package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.Customer;
import com.eling.elcms.travel.model.view.QueryAllIntentionView;
import com.eling.elcms.travel.service.ICustomerManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CustomerController extends BaseFormController {

	@Autowired
	ICustomerManager customerManager;

	@RequestMapping("/api/customer/search*")
	@ResponseBody
	public List<Customer> sreach(@ModelAttribute SearchCondition sc, @ModelAttribute Customer cond) {
		sc.setQueryCondition(cond);
		return customerManager.search(sc);
	}

	@RequestMapping("/api/customer/query")
	@ResponseBody
	public List<Customer> query(@ModelAttribute Customer cond) {
		return customerManager.query(cond);
	}

	@RequestMapping("/api/customer/save")
	@ResponseBody
	public Customer save(@ModelAttribute @ModelFilling Customer cond) {
		return customerManager.save(cond);
	}

	@RequestMapping("/api/customer/{pkCustomer}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCustomer) {
		customerManager.remove(pkCustomer);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/customer/queryall")
	@ResponseBody
	public List<Customer> queryAll(@ModelAttribute Customer cond) {
		return customerManager.queryAll(cond);
	}
	
	/*
	 * 查询满意度
	 */
	@RequestMapping("/api/customer/queryAllIntention")
	@ResponseBody
	public List<QueryAllIntentionView> queryAllIntention(@ModelAttribute Customer cond){
		return customerManager.queryAllIntention(cond);
	}
}
